
let  VSHADER_SOURCE = 
	'attribute vec4 a_Position;\n' + 
	'attribute float a_PointSize;\n' + 
	'void main() {\n' + 
	' 	gl_Position = a_Position;\n' + //设置坐标
	' 	gl_PointSize = a_PointSize;\n' +  //设置尺寸
	'}\n';

let FAHADER_SOURCE = 
	'void main() {\n' + 
	'	gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n' + //设置颜色
	'}\n';

function main() {
	// body...
	let canvas = document.getElementById('webgl');

	//获取WebGL绘图上下文
	let gl = getWebGLContext(canvas);
	if (!gl) {
		console.log("Failed to get the rendering context for WebGL");
		return;
	}

	if (!initShaders(gl, VSHADER_SOURCE, FAHADER_SOURCE)) {
		console.log("Failed to initialize shaders");
		return;
	}

	let a_Position = gl.getAttribLocation(gl.program, 'a_Position');
	let a_PointSize= gl.getAttribLocation(gl.program, 'a_PointSize');

	if (a_Position < 0) {
		console.log("Failed to get the storage location of a_Position");
		return;
	}

	//将顶点位置传输给attribute变量
	gl.vertexAttrib3f(a_Position, 0.0, 0.0, 0.0);

	gl.vertexAttrib1f(a_PointSize, 20.0);

	//指定清空<canvas>的颜色
	gl.clearColor(0.0, 0.0, 0.0, 1.0);

	//清空<canvas>
	gl.clear(gl.COLOR_BUFFER_BIT);

	//绘制一个点
	gl.drawArrays(gl.POINTS, 0, 1);
}